package com.xinongbest.mall.thread;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class ThreadJoin {
    public static void main(String[] args) {
        ThreadDemo task = new ThreadDemo();
        FutureTask<Integer> futureTask = new FutureTask<>(task);
        Thread thread = new Thread(futureTask);
        thread.start();
        try {
            Integer i = futureTask.get();
            System.out.println("计算结果是：" + i);
        } catch (InterruptedException | ExecutionException e) {
            throw new RuntimeException(e);
        }
    }
}


class ThreadDemo implements Callable<Integer> {
    @Override
    public Integer call() throws Exception {
        Thread.sleep(200);
        return 100 + 200;
    }
}